import pymysql
from dotenv import load_dotenv
import os

# 加载.env文件
load_dotenv()


def create_conn():
    host = os.getenv('MYSQL_HOST')
    user = os.getenv('MYSQL_USER')
    password = os.getenv('MYSQL_PASSWORD')
    db = os.getenv('MYSQL_DB')

    conn = pymysql.connect(host=host, user=user, password=password, db=db)
    return conn


def close_conn(conn):
    if conn:
        conn.close()
